package com.hspedu.newData.dmsxl.数组;
/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-15 
 * @Version: 1.0
 */

public class LC5最长回文子串 {

    // 纯暴力
    public String longestPalindrome(String s) {

        int count = 0;
        int left = 0;
        int right = 0;
        for (int i = 0; i < s.length(); i++) {
            for (int j = s.length(); j >= i; j--) {
                if (isPalindrome(s.substring(i,j))){
                    if (count < j - i){
                        count = j - i;
                        left = i;
                        right = j;
                        break;
                    }
                }
            }
        }
        return s.substring(left,right);
    }


    public boolean isPalindrome(String s){
        int i = 0;
        int j = s.length() - 1;

        while (i<j){

            if (s.charAt(i) != s.charAt(j)){
                return false;
            }
            i++;
            j--;
        }
        return true;
    }
}
